//
//  CommentView.m
//  FNMenu
//
//  Created by 航汇聚科技 on 2018/9/25.
//  Copyright © 2018年 Yi Zhou. All rights reserved.
//

#import "CommentView.h"
@implementation CommentView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    self = [[[NSBundle mainBundle] loadNibNamed:@"CommentView" owner:self options:nil] lastObject];
    if (self) {
        self.frame = frame;
    }
    self.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.layer.borderWidth = .5;
    self.textView.delegate = self;
    return self;
}
#pragma mark - UITextViewDelegate
- (void)textViewDidBeginEditing:(UITextView *)textView {
    CGRect textSize = [textView.text boundingRectWithSize:CGSizeMake(textView.bounds.size.width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont fontWithName:@"AppleSDGothicNeo-Regular" size:17.0]} context:nil];
    if (self.textViewDidChange) {
        self.textViewDidChange(textSize.size);
    }
}
- (void)textViewDidChange:(UITextView *)textView {
    self.placeholdLabel.hidden = textView.text.length > 0 ? YES : NO;
    CGRect textSize = [textView.text boundingRectWithSize:CGSizeMake(textView.bounds.size.width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont fontWithName:@"AppleSDGothicNeo-Regular" size:17.0]} context:nil];
    if (self.textViewDidChange) {
        self.textViewDidChange(textSize.size);
    }
}
#pragma mark - event response
- (IBAction)sendCommentAction:(UIButton *)sender {
    if (self.sendCommentContent) {
        self.sendCommentContent(self.textView.text);
    }
}

@end
